//
//  AddBankCardVC.m
//  Logistics
//
//  Created by enzhoukeji on 2018/8/11.
//  Copyright © 2018年 puyue.com. All rights reserved.
//

#import "AddBankCardVC.h"
#import "AddBankTVCell.h"
@interface AddBankCardVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property (nonatomic,strong) UITableView *addBankTV;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) UIButton *conButton;
@end

@implementation AddBankCardVC
-(UITableView *)addBankTV{
    if (!_addBankTV) {
        _addBankTV = [[UITableView alloc]initWithFrame:CGRectMake(GTFixWidthFlaot(20),  kMainTopHeight, kMainScreen_width-GTFixWidthFlaot(40) , kMainScreen_height-kMainTopHeight - GTFixHeightFlaot(80)) style:UITableViewStyleGrouped];
        _addBankTV.showsVerticalScrollIndicator = NO;
        _addBankTV.backgroundColor = [UIColor whiteColor];
        _addBankTV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _addBankTV.dataSource = self;
        _addBankTV.delegate = self;
    }
    return _addBankTV;
}
-(NSArray *)titleArray {
    if (!_titleArray) {
        _titleArray = [NSArray arrayWithObjects:@"真实姓名",@"身份证号",@"银行卡号",@"手机号码",nil];
    }
    return _titleArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"添加银行卡";
    [self.view addSubview:self.addBankTV];
    [self createUI];
    // Do any additional setup after loading the view.
}
-(void)createUI {
    self.conButton = [UIButton buttonWithTitle:@"确定" withImageName:nil withBGColor:[UIColor grayColor] Withlayer:NO];
    self.conButton.layer.cornerRadius = 5.0;
    [self.view addSubview:self.conButton];
    [self.conButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(GTFixWidthFlaot(15));
        make.bottom.mas_equalTo(GTFixHeightFlaot(-30));
        make.width.mas_equalTo(kMainScreen_width - GTFixWidthFlaot(30));
        make.height.mas_equalTo(GTFixHeightFlaot(30));
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AddBankTVCell *cell=[tableView dequeueReusableCellWithIdentifier:@"AddBankTVCell"];
    if (!cell) {
        cell=[[AddBankTVCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AddBankTVCell"];
    }
    cell.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    cell.layer.cornerRadius = 5;
    cell.testFl.delegate =self;
    cell.testFl.tag = 100 + indexPath.section;
    if (indexPath.section == 0 ) {
        cell.testFl.text = @"马**";

    }else if (indexPath.section == 1){
          cell.testFl.text = @"3709132***********4444";
        
    }else if (indexPath.section == 2 ){
        
        cell.testFl.placeholder = @"请填写银行卡号";

    }else  {
        cell.testFl.placeholder = @"请输入正确的银行预留手机号";

    }
    cell.realNameLabel.text = self.titleArray[indexPath.section];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 3) {
        UIView * footView = [UIView new];
        UILabel * label = [UILabel labelWithSize:[UIFont systemFontOfSize:13] withColor:[UIColor grayColor] withText:@"暂不支持信用卡"];
        [footView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(GTFixHeightFlaot(10));
            make.left.mas_equalTo(GTFixWidthFlaot(5));
            make.height.mas_equalTo(GTFixHeightFlaot(15));
            make.width.mas_equalTo(label.mas_width);
        }];
        return footView;
    }else{
        return nil;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        UIView * headView = [UIView new];
        UILabel * label = [UILabel labelWithSize:[UIFont systemFontOfSize:14] withColor:[UIColor grayColor] withText:@"此处添加的银行卡只可用于提现！为了保障资金安全，请添加本人的银行卡"];
        label.numberOfLines = 0;
        [headView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.left.mas_equalTo(GTFixWidthFlaot(0));
            make.height.mas_equalTo(GTFixHeightFlaot(40));
            make.width.mas_equalTo(kMainScreen_width - GTFixWidthFlaot(40));
        }];
        return headView;
    }else{
        return nil;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return GTFixHeightFlaot(35);
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 3) {
         return GTFixHeightFlaot(30);
    }else{
        return GTFixHeightFlaot(5);
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return GTFixHeightFlaot(50);
    }else{
        return GTFixHeightFlaot(5);
    }
  
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == 100 || textField.tag == 101) {
        return NO;
    }else{
        return YES;
    }
}
//- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
//    if (textField.tag == 102 || textField.tag == 103) {
//        text
//    }
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
